const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

/**
 * 删除数组中的某一个对象
 * @param arr {Array} 数组
 * @param obj {Object} 需要删除的对象
 * @returns {Array} 处理之后的数组
 */
const arrRemoveObj = (arr, obj) => {
  let len = arr.length;
  for (let i = 0; i < len; i++) {
    if (arr[i] === obj) {
      if (i === 0) {
        arr.shift();
        return arr;
      } else if (i === len - 1) {
        arr.pop();
        return arr;
      } else {
        arr.splice(i, 1);
        return arr;
      }
    }
  }
};
 


module.exports = {
  arrRemoveObj: arrRemoveObj,
  formatTime
}
